package com.kolon.business.mngr.service.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.business.mngr.service.dao.ServiceDao;
import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;

@Controller("com.kolon.business.mngr.service.controller.ServiceDeleteController")
public class ServiceDeleteController implements SimpleController {

	@Resource(name="com.kolon.business.mngr.service.dao.ServiceDaoImpl")
	private ServiceDao serviceDao;
	
	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mngr/service/serviceDelete.do")
	public ModelAndView controller(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
		
		Map<String, String> map = new HashMap<String, String>();
		// 파라미터
		int page = ComUtil.sToi(ComUtil.nullChk(request.getParameter("page"), "1"));
		String servNo = ComUtil.nullChk(request.getParameter("servNo"));
		String schTp = ComUtil.nullChk(request.getParameter("schTp"));
		String schTxt = ComUtil.nullChk(request.getParameter("schTxt"));
		// 파일 저장 경로
		// String iconUploadPath = MsgUtil.getMessage("service.icon.path");
		// String appUploadPath = MsgUtil.getMessage("app.file.path");
		// 회원 세션 정보
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_MNGR_INFO);
		map.put("mdfyId", (String)userMap.get("MNGR_ID"));
		map.put("servNo", servNo);
		map.put("useYn", "N");
		// 서비스 정보 조회
		Map servMap = serviceDao.getMap(map);
		if (servMap != null) {
			// 사용여부 수정
			serviceDao.updateUseYn(map);
			if (servMap.get("CPY_CD") != null)
			serviceDao.updateTeamAllUseYn(map);
			/*
			// 데이터 및 이미지 아이콘 및 앱 히스토리 삭제
			serviceDao.deleteServInfo(map);
			FileUtil.dirDelete(new File(appUploadPath + ComUtil.oTos(servMap.get("FRF_TP")).toLowerCase()
					+ File.separator + servMap.get("FDR_NM")));
			// 서비스 팀 정보 삭제
			serviceDao.deleteServTeamList(map);
			// 서비스 삭제
			serviceDao.delete(map);
			FileUtil.delFile(iconUploadPath + servMap.get("IMG_NM"));
			*/
		}
		// 리턴
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("redirect:/business/mngr/service/serviceList.do");
		modelAndView.addObject("page", page);
		modelAndView.addObject("schTp", schTp);
		modelAndView.addObject("schTxt", schTxt);
		return modelAndView;
	}
}
